package bizlogic;

import java.sql.SQLException;

import java.util.ArrayList;

import dao.*;
import model.*;

public class Employee {

	private EmployeeDAO empDAO;

	public Employee() {
		empDAO = DAOFactory.loadInstance().getEmployeeDAO();
	}
	
	@SuppressWarnings("finally")
	public EmployeeDTO FindEmployeeByUserPass(String employeeEmail,
			String employeePassword)
	{
		EmployeeDTO currentEmployee = new EmployeeDTO();
		try {
			currentEmployee = empDAO.FindEmployeeByUserPass(employeeEmail, employeePassword);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentEmployee;
		}
	}
	
	@SuppressWarnings("finally")
	public ArrayList<EmployeeDTO> findAllManager() {
		ArrayList<EmployeeDTO> currentList = new ArrayList<EmployeeDTO>();
		try {
			currentList = empDAO.findAllManager();
		} finally {
			return currentList;
		}
	}
	
	@SuppressWarnings("finally")
	public ArrayList<EmployeeDTO> findEmployeesByCriteria(EmployeeSearchDTO empso) {
		ArrayList<EmployeeDTO> currentList = new ArrayList<EmployeeDTO>();
		try {
			currentList = empDAO.findEmployeeByCriteria(empso);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentList;
		}
	}
	
	@SuppressWarnings("finally")	
	public EmployeeDTO findEmployee(String employeeName)
	{
		EmployeeDTO currentEmployee = new EmployeeDTO();
		try {
			currentEmployee = empDAO.findEmployee(employeeName);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentEmployee;
		}
	}
	
	@SuppressWarnings("finally")
	public EmployeeDTO findEmployeewithename(String firstName)
	{
		EmployeeDTO currentEmployee = new EmployeeDTO();
		try {
			currentEmployee = empDAO.findEmployeewithfname(firstName);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentEmployee;
		}
	}
	
	@SuppressWarnings("finally")
	public EmployeeDTO findEmployee(int employeeID) {
		EmployeeDTO currentEmployee = new EmployeeDTO();
		try {
			currentEmployee = empDAO.findEmployee(employeeID);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentEmployee;
		}
	}
	
	@SuppressWarnings("finally")
	public ArrayList<EmployeeDTO> findEmployeeByManager(int managerID,String status) {
		ArrayList<EmployeeDTO> currentList = new ArrayList<EmployeeDTO>();
		try {
			currentList = empDAO.findEmployeeByManager(managerID,status);
			System.out.println("outputtttt="+currentList.toString());
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentList;
		}
	}	
	
	@SuppressWarnings("finally")
	public ArrayList<EmployeeDTO> findAllEmployee() {
		ArrayList<EmployeeDTO> currentList = new ArrayList<EmployeeDTO>();
		try {
			currentList = empDAO.findAllEmployee();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentList;
		}
	}

	public void updateEmployee(EmployeeDTO employee) throws SQLException {
		try {
			empDAO.updateEmployee(employee);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void deleteEmployee(EmployeeDTO employee) throws SQLException {
		try {
			empDAO.deleteEmployee(employee);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void insertEmployee(EmployeeDTO employee) throws SQLException {
		empDAO.addEmployee(employee);
	}
}
